package cn.xingzhe.monster.user.application.converter;

import cn.xingzhe.monster.user.application.dto.RoleDTO;
import cn.xingzhe.monster.user.domain.model.RoleModel;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

/**
 * 角色转换器
 * 负责 RoleModel 和 RoleDTO 之间的转换
 *
 * @author System
 * @version 1.0.0
 * @since 2024-01-01
 */
@Mapper(componentModel = "spring")
public interface RoleConverter {

    RoleConverter INSTANCE = Mappers.getMapper(RoleConverter.class);

    /**
     * 领域模型转DTO
     *
     * @param model 角色领域模型
     * @return 角色DTO
     */
    @Mapping(target = "permissions", ignore = true)
    RoleDTO toDTO(RoleModel model);

    /**
     * DTO转领域模型
     *
     * @param dto 角色DTO
     * @return 角色领域模型
     */
    @Mapping(target = "id", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    RoleModel fromDTO(RoleDTO dto);
}

